<?php

namespace App\Http\Controllers;

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function validate($request, $rules, $message){
        $Validator = Validator::make($request->all(),$rules,$message);
        if($Validator->fails()){
            $result = [];
            foreach(json_decode(json_encode($Validator->errors()),true) as $k => $v){
                $result[$k] = $v[0];
            }
            echo json_encode($result);
            die;
        }
    }
}
